import axios from "axios";

const client = axios.create({
  baseURL: "http://localhost:8050",
  // 访问后端超时时间
  timeout: 5000,
});

// 响应拦截器
client.interceptors.response.use(
  // 成功回调
  (response) => {
    return response.data;
  },

  // 失败回调
  (error) => {
    console.log(error);
    // 处理网络error
    let errMsg = `${error.code}: ${error.message}`;

    // 处理业务error
    if (error.response) {
      errMsg = error.response.data.message;
    }

    return Promise.reject(new Error(errMsg));
  }
);

export default client;
